<template>
  <yy-paging
    v-model="dataList"
    @query="queryList"
    ref="paging"
    :auto="automatic"
    @scroll="scroll"
    :refresher-enabled="false"
  >
    <template #top>
      <u-navbar
        :is-back="false"
        :background="{ backgroundColor: isScroll ? '#F2F5F7' : 'transparent' }"
        :border-bottom="false"
        :custom-style="{ transition: 'background-color 0.3s ease-in-out' }"
      >
        <view class="grid grid-cols-3 items-center px-3 w-full">
          <view class="flex col-span-1 items-center" @click="vk.navigateBack()">
            <image src="/static/dddr128.png" mode="aspectFill" class="size-6" />
          </view>
          <view class="line-clamp-1 flex col-span-1 justify-center">
            <view class="text-[#000] font-bold text-base"> 个人简介 </view>
          </view>
          <view class="flex col-span-1 justify-end">
            <view
              class="w-[4.25rem] h-[1.75rem] bg-[#00A9AB] rounded-full flex justify-center items-center btn"
              @click="complete"
            >
              <view class="text-[.875rem] text-[#FFFFFF]"> 完成 </view>
            </view>
          </view>
        </view>
      </u-navbar>
    </template>
    <template #empty>
      <yy-empty></yy-empty>
    </template>
    <template #loadingMoreNoMore>
      <yy-nomore></yy-nomore>
    </template>
    <view class="p-4">
      <view class="w-full bg-[#FFFFFF] rounded-[.75rem] p-3 flex flex-col gap-1">
        <textarea
          name=""
          placeholder="请输入个人介绍"
          :maxlength="maxlength"
          focus
          v-model="nickname"
          class="w-full"
          rows="2"
          :adjust-position="false"
        ></textarea>
        <view class="flex justify-end">
          <view class="text-[.6875rem] text-[#8E9299]">{{ nickname.length }}/{{ maxlength }}</view>
        </view>
      </view>
    </view>
  </yy-paging>
</template>

<script>
  export default {
    data() {
      return {
        isScroll: false, // 控制页面滚动状态
        maxlength: 200, // 最大输入长度
        dataList: [], // 分页数据列表
        automatic: false, // 是否自动加载数据
        nickname: '' // 用户昵称
      }
    },
    onLoad(e) {
      this.nickname = e.nickname
    },
    methods: {
      scroll(e) {
        // this.isScroll = e.detail.scrollTop > 0
      },
      async complete() {
        if (!this.nickname) return vk.toast('请输入个人介绍', 'none')
        let res = await api.editInfo({ motto: this.nickname.trim() })
        vk.toast(res.msg)
        if (!res.code) return
        vk.vuex.dispatch('$user/getUserInfo')
        vk.navigateBack()
      },

      async queryList(page, limit) {
        this.$refs.paging.complete([1, 1, 1])
      }
    }
  }
</script>

<style lang="scss" scoped></style>
